﻿@model Message
@Html.Extra()
@{
    Layout = "~/Views/Shared/OA/_Edit.cshtml";
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "保存", Click = "save" })
    @Html.MyNet().Button(new ButtonOptions { Text = "返回", Click = "back" })
}
@section Main
{
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.CreateTime)
    @Html.HiddenFor(model => model.AttachmentKey)
    @Html.Hidden("ReceiverIds","")
    <table>
        @*<tr>
            <th>
                <b>*</b>@Html.LabelFor(model => model.Type, "发送人群")
            </th>
            <td>
                @Html.MyNet().DropDownListFor(model => model.Type, new[]{
                new { Value = (int)MessageType.All, Name = MessageType.All.ToText()},
                new { Value = (int)MessageType.Agent, Name = MessageType.Agent.ToText()},
                new { Value = (int)MessageType.AgentChannel, Name = MessageType.AgentChannel.ToText()}
           }, "Value", "Name", "请选择发送人群", new ValidateOptions
                {
                    RequiredError = "请选择发送人群"
                })
                @Html.MyNet().ValidationMessageFor(model => model.Type)
            </td>
        </tr>*@
        <tr>
            <th>
                <b>*</b>接收人：
            </th>
            <td>
                @Html.MyNet().TextBox("ReceiverNames","", new ValidateOptions
                        {
                            RequiredError = "请选择接收人"
                        })
                <input type="button" onclick="pickerUser()" class="k-button" value="选择接收人">
            </td>
        </tr>
        <tr>
            <th>
                <b>*</b>@Html.LabelFor(model => model.Title, "标题")
            </th>
            <td>
                @Html.MyNet().TextBoxFor(model => model.Title, new ValidateOptions
                {
                    RequiredError = "请输入标题"
                })
                @Html.MyNet().ValidationMessageFor(model => model.Title)
            </td>
        </tr>
        <tr>
            <th>
                <b>*</b>@Html.LabelFor(model => model.Content, "内容")
            </th>
            <td>
                @Html.MyNet().TextAreaFor(model => model.Content, new ValidateOptions
                {
                    RequiredError = "请输入内容"
                })
                @Html.MyNet().ValidationMessageFor(model => model.Content)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.Image, "图片")
            </th>
            <td>
                @Html.MyNet().UploadFor(model => model.Image, new UploadOptions
                   {
                       AttachmentKey = Model.AttachmentKey,
                       AttachmentTypeKey = "MessageImage",
                       UploadMode = UploadMode.ImageSingle
                   })
            </td>
        </tr>
    </table>
}
<script>

    function save() {
        var form = $("form");
        if (!form.valid()) return;

        $.ajax
        ({
            url: form.attr("action"),
            data: form.serialize(),
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                back(true, null);
            }
        });
    }

    function pickerUser() {
        top.winOpen(
             {
                 width: 800,
                 height: 400,
                 modal: true,
                 iframe: true,
                 content: "/Common/User/IndexForPickerMore?Application=MK",
                 title: "人员选择"
             }, function (data) {
                 console.log(data)
                 $("#UserId").val(data.ids);
                 $("#UserName").html(data.userName);

                 var dataIds = $("#ReceiverIds").val();
                 var dataNames= $("#ReceiverNames").val()
                 if (dataIds == "") {
                     dataIds = data.ids;
                     dataNames = data.userNames;
                 } else {
                     dataNames += ",";
                     dataNames += data.userNames;
                 }
                 $("#ReceiverIds").val(dataIds);
                 $("#ReceiverNames").val(dataNames);
             })
    }
</script>
